package com.datang.petstore.resultpage;



/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-05-09 19:55
 * @notify 全局API返回值包装类
 * @version 1.0
 */


import java.io.Serializable;

public class Result implements Serializable {

    private String code;
    private String message;
    private Object data;

    /*
     * @author 顶风少年
     * @date 2019/5/9 23:24
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param code 状态码
     * @param message 返回说明
     * @param data 返回数据
     * @result
     * @notify
     * version 1.0
     */
    private Result(ResultCode resultCode, Object data) {
        this.data = data;
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public static Result ok() {
        return new Result(ResultCode.success, null);
    }

    public static Result ok(Object data) {
        return new Result(ResultCode.success, data);
    }


    public static Result err(ResultCode resultCode) {
        return new Result(resultCode, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
